package com.leizhi.demo.monitor.controller;

import com.leizhi.demo.monitor.pojo.UserDto;
import com.leizhi.demo.monitor.pojo.WebResult;
import com.leizhi.demo.monitor.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 用户控制器（只实现简单的登录）
 * @Version 1.0.0-SNAPSHOT
 * @Author leizhi
 * @Date 2025/4/29 15:27
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    public WebResult login(@RequestBody UserDto dto) {
        try {
            String token = userService.login(dto);
            return WebResult.successWithData("登录成功", token);
        } catch (Exception e) {
            return WebResult.error(e.getMessage());
        }
    }

}
